package com.cdie.myschool.mapper.StudentTermReportMapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cdie.myschool.domain.entity.BookHistory;
import com.cdie.myschool.domain.entity.Library;
import com.cdie.myschool.domain.vo.LibraryVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @program:my-school
 * @ClassName:LibraryMapper
 * @Description:图书馆信息
 * @author:毛康源
 * @data:2022-10-13 9:46
 **/
@Mapper
public interface LibraryMapper extends BaseMapper<Library> {
    @Select("select return_date from book_borrowing_history where reader_id=#{readerId}")
    List<BookHistory> getreturnDate(String readerId);

    @Select("select sum(stay_time)  from library_pass_record where user_id=#{readerId} and semester_id=#{semesterId}")
    Integer getSum(String readerId,Integer semesterId );

    @Select("SELECT user_id,sum(stay_time) FROM `library_pass_record` GROUP BY `user_id` ORDER BY sum(stay_time) DESC")
    List<Library> getRank();

    @Select("SELECT @rownum:=@rownum+1 AS rownum,l.user_id,sum(l.stay_time) FROM (SELECT @rownum:=0) r, library_pass_record as l  GROUP BY user_id ")
    List<Library> getRankSum();

    @Select("SELECT @rownum:=@rownum+1 AS rownum,l.user_id,sum(l.stay_time) FROM (SELECT @rownum:=0) r, library_pass_record as l  GROUP BY user_id HAVING user_id=#{userId}")
    LibraryVO getRankUser(String userId);


}
